﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BI.CF.Model;
using BI.CF.BLL;
using BI.CF.PageList;
using System.Data.SqlClient;
namespace BackStage.Hand
{
    /// <summary>
    /// MemLoan_Shows 的摘要说明
    /// </summary>
    public class MemLoan_Shows : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int pageindex = Convert.ToInt32(context.Request["pageindex"]);//当前页数
            int pagesize = Convert.ToInt32(context.Request["pagesize"]);//当前总页数
            string username = context.Request["usersname"].ToString();//用户名
            decimal moneloan;//要查询的金额
            string ss = context.Request["money"].ToString();
            if (ss == "")
            {
                moneloan = 0;
            }
            else
            {
                moneloan = Convert.ToDecimal(context.Request["money"].ToString());
            }
            
            string fuhao = context.Request["fuhao"].ToString();//比较符号
            MemLoanBLL MLbll = new MemLoanBLL();
            Pager<MemLoanModel> mlmpager = new Pager<MemLoanModel>();
            List<MemLoanModel> list = new List<MemLoanModel>();
            SqlDataReader read = MLbll.Show_MemlLoan(pageindex, pagesize, username, moneloan, fuhao);
            while (read.Read())
            {
                MemLoanModel m = new MemLoanModel();
                m.MemLoanId = Convert.ToInt32(read["MemLoanId"].ToString());
                m.UserName = read["UserName"].ToString();
                m.Title = read["Title"].ToString();
                m.LoanMoney = Convert.ToDecimal(read["LoanMoney"].ToString());
                m.RepaymentModeId = read["RepaymentModeId"].ToString();
                m.LoanTerm = Convert.ToInt32(read["LoanTerm"].ToString());
                m.ExamineState = read["ExamineState"].ToString();
                m.EndLoanTime = DateTime.Parse(read["EndLoanTime"].ToString());
                m.AlreadyRaiseLoan = decimal.Parse(read["AlreadyRaiseLoan"].ToString());
                m.Annualrate = float.Parse(read["Annualrate"].ToString());
                m.LaunchLoanTime = DateTime.Parse(read["LaunchLoanTime"].ToString());
                m.LoanExplain = read["LoanExplain"].ToString();
                m.LoanPurpose = read["LoanPurpose"].ToString();
                m.LoanRaise =Convert.ToInt32(read["LoanRaise"]);
                m.LoanType = read["LoanType"].ToString();
                m.PayInterest = decimal.Parse(read["PayInterest"].ToString());
                m.RepaymentDay = DateTime.Parse(read["RepaymentDay"].ToString());
                m.RepaySumMoney = decimal.Parse(read["RepaySumMoney"].ToString());
                m.TotalTransactions = int.Parse(read["TotalTransactions"].ToString());
                m.UserrId = int.Parse(read["UserrId"].ToString());
                list.Add(m);
            }
            mlmpager.Data = list;
            mlmpager.PageIndex = pageindex;
            mlmpager.PageSize = pagesize;
            int datacount = MLbll.Count_MemLoan(username, moneloan, "请选择");//当前数据的总条数
            if (datacount % pagesize == 0)
            {
                mlmpager.PageCount = datacount / pagesize;
            }
            else
            {
                mlmpager.PageCount = (datacount / pagesize) + 1;
            }
            string str = JsonHelper.JsonSerializer<Pager<MemLoanModel>>(mlmpager);
            context.Response.Write(str);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}